/**
 * Created by LeungZ on 2016/3/15.
 */
class LoginCtrl {
    constructor(userSrv, $location, $state, $rootScope, uiNotification) {
        "ngInject";
        this._location = $location;
        this._userSrv = userSrv;
        this._state = $state;
        this._rootScope = $rootScope;
        this._uiNotification = uiNotification;
    }

    submit() {
        this._userSrv.login(this).then(data => {
            this.$login_error = '';
            this._userSrv.getUserInfo().then(data=> {
                // console.log(data.user);
                this._rootScope.user = data.user;
                localStorage.setItem('myUser',JSON.stringify(data.user))
            }).catch(function (data) {
                this._uiNotification.error({
                    title: '用户信息',
                    message: '获取用户信息数据有误'
                });
            });
            this._state.go('welcome');
        }).catch(data=> {
            this.$login_error = data.resultMsg;
        });
    }
}
export default LoginCtrl;
